package com.kirayous.api.blog.mapper;

import com.kirayous.common.dto.ArticleBackDTO;
import com.kirayous.common.dto.ArticleStatisticsDTO;
import com.kirayous.common.entity.Article;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kirayous.common.vo.ConditionVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author KiraYous
 * @since 2021-09-23
 */
@Mapper
public interface ArticleMapper extends BaseMapper<Article> {

    /**
     * 文章统计
     *
     * @return {@link List<ArticleStatisticsDTO>} 文章统计结果
     */
    @Select("        SELECT\n" +
            "            DATE_FORMAT( create_time, \"%Y-%m-%d\" ) AS date,\n" +
            "            COUNT( 1 ) AS count\n" +
            "        FROM\n" +
            "            tb_article\n" +
            "        GROUP BY\n" +
            "            date\n" +
            "        ORDER BY\n" +
            "            date DESC")
    List<ArticleStatisticsDTO> listArticleStatistics();

    /**
     * 查询后台文章总量
     *
     * @param condition 条件
     * @return 文章总量
     */
    Integer countArticleBacks(@Param("condition") ConditionVO condition);

    /**
     * 查询后台文章
     *
     * @param current   页码
     * @param size      大小
     * @param condition 条件
     * @return 文章列表
     */
    List<ArticleBackDTO> listArticleBacks(@Param("current") Long current, @Param("size") Long size, @Param("condition") ConditionVO condition);

}
